#include "imgui_filedialog.h"
#include "ImGuiFileDialog.h"
#include "imgui.h"

namespace {
ImVec2 btn_size{200, 60};
}

void open_file() {
  static std::string filePathName;
  static std::string filePath;
  if (ImGui::Button("打开文件", btn_size)) {
    filePathName = "";
    filePath = "";
    IGFD::FileDialogConfig config;
    config.path = "C:\\wow\\classic_wlk\\script";
    ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "选择文件",
                                            ".lua,.*", config);
  }
  if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey")) {
    if (ImGuiFileDialog::Instance()->IsOk()) {
      filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
      filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
      // Do actions
    }
    ImGuiFileDialog::Instance()->Close();
  }
  // 显示
  ImGui::SameLine();
  ImGui::Text("%s", filePathName.c_str());
}
